package com.jhc.drone.communication.datagram.ack;


import com.jhc.drone.communication.mavlink.common.msg_command_ack;
import com.jhc.drone.communication.mavlink.common.msg_mission_ack;
import com.jhc.drone.communication.mavlink.common.msg_mission_request;
import com.jhc.drone.communication.mavlink.common.msg_mission_request_int;
import com.jhc.drone.communication.mavlink.enums.MAV_CMD;
import com.jhc.drone.communication.mavlink.enums.MAV_MISSION_RESULT;
import com.jhc.drone.communication.mavlink.enums.MAV_RESULT;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lcp
 * @date 2025年01月2025/1/8 10:56
 * @describe
 */
@Slf4j
public class Ack {

    public static void ack(msg_command_ack commandAck){
        switch (commandAck.command) {
            case MAV_CMD.MAV_CMD_COMPONENT_ARM_DISARM:
                // 解锁
                checkResult(commandAck,"arm");
                break;
            case MAV_CMD.MAV_CMD_NAV_TAKEOFF:
                // 起飞
                checkResult(commandAck,"takeoff");
                break;
            case MAV_CMD.MAV_CMD_NAV_LAND:
                // 降落
                checkResult(commandAck,"land");
                break;
            case MAV_CMD.MAV_CMD_NAV_RETURN_TO_LAUNCH:
                // 返航
                checkResult(commandAck,"return_to_launch");
                break;
            case MAV_CMD.MAV_CMD_DO_SET_MODE:
                checkResult(commandAck,"do_set_mode");
                break;
            case MAV_CMD.MAV_CMD_DO_PAUSE_CONTINUE:
                checkResult(commandAck,"do_pause_continue");
                break;
            case MAV_CMD.MAV_CMD_DO_SET_HOME:
                checkResult(commandAck,"do_set_home");
                if(commandAck.result == MAV_RESULT.MAV_RESULT_ACCEPTED){
                    // set home success

                }
                break;
            default:
                break;
        }
    }



    public static void ack(msg_mission_ack missionAck){
        switch (missionAck.type) {
            case MAV_MISSION_RESULT.MAV_MISSION_ACCEPTED:
                log.info("ack check result mission【{}】 accepted",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_ERROR:
                log.error("ack check result mission【{}】 error",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_UNSUPPORTED_FRAME:
                log.error("ack check result mission【{}】 unsupported frame",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_UNSUPPORTED:
                log.error("ack check result mission【{}】 unsupported",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_INVALID:
                log.info("ack check result mission【{}】 invalid",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_INVALID_PARAM1:
                log.info("ack check result mission【{}】 invalid param1",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_INVALID_PARAM2:
                log.info("ack check result mission【{}】 invalid param2",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_NO_SPACE:
                log.info("ack check result mission【{}】 no space",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_INVALID_PARAM3:
                log.info("ack check result mission【{}】 invalid param3",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_INVALID_PARAM4:
                log.info("ack check result mission【{}】 invalid param4",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_INVALID_PARAM5_X:
                log.info("ack check result mission【{}】 invalid param5_X",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_INVALID_PARAM6_Y:
                log.info("ack check result mission【{}】 invalid param6_Y",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_INVALID_PARAM7:
                log.info("ack check result mission【{}】 invalid param7",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_DENIED:
                log.info("ack check result mission【{}】 denied",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_OPERATION_CANCELLED:
                log.info("ack check result mission【{}】 cancelled",missionAck.type);
                break;
            case MAV_MISSION_RESULT.MAV_MISSION_RESULT_ENUM_END:
                log.info("ack check result mission【{}】 enum end",missionAck.type);
                break;
            default:
                break;
        }
    }

    public static void ack(msg_mission_request_int missionRequest) {
        System.out.println(missionRequest);
    }

    private static void checkResult(msg_command_ack commandAck, String command){
        switch (commandAck.result) {
            case MAV_RESULT.MAV_RESULT_ACCEPTED:
                log.info("ack check result 【{}】 accepted",command);
                break;
            case MAV_RESULT.MAV_RESULT_DENIED:
                log.error("ack check result 【{}】 denied",command);
                break;
            case MAV_RESULT.MAV_RESULT_FAILED:
                log.error("ack check result 【{}】 failed",command);
                break;
            case MAV_RESULT.MAV_RESULT_CANCELLED:
                log.error("ack check result 【{}】 canceled",command);
                break;
            case MAV_RESULT.MAV_RESULT_TEMPORARILY_REJECTED:
                log.error("ack check result 【{}】 temporarily rejected",command);
                break;
            case MAV_RESULT.MAV_RESULT_UNSUPPORTED:
                log.error("ack check result 【{}】 unsupported",command);
                break;
            case MAV_RESULT.MAV_RESULT_IN_PROGRESS:
                log.info("ack check result 【{}】 in progress",command);
                break;
            case MAV_RESULT.MAV_RESULT_COMMAND_LONG_ONLY:
                log.warn("ack check result 【{}】 command long only",command);
                break;
            case MAV_RESULT.MAV_RESULT_COMMAND_INT_ONLY:
                log.warn("ack check result 【{}】 command int only",command);
                break;
            case MAV_RESULT.MAV_RESULT_COMMAND_UNSUPPORTED_MAV_FRAME:
                log.error("ack check result 【{}】 unsupported mav frame",command);
                break;
            case MAV_RESULT.MAV_RESULT_ENUM_END:
                log.warn("ack check result 【{}】 enum end ",command);
                break;
            default:
                break;
        }
    }
}
